package com.bclz.environment;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Environment implements WritableComparable<Environment> {



    private String yearAndMonth;

    private Integer temperature;



    @Override
    public void write(DataOutput c) throws IOException {

        c.writeUTF(this.yearAndMonth);
        c.writeInt(this.temperature);

    }

    @Override
    public void readFields(DataInput in) throws IOException {

        this.yearAndMonth=in.readUTF();
        this.temperature=in.readInt();

    }

    /**
     * 升序
     * @param o
     * @return
     */
    @Override
    public int compareTo(Environment o) {
        int compareInt=this.yearAndMonth.compareTo(o.getYearAndMonth());
        if(compareInt==0){

            compareInt=this.temperature-o.temperature;

        }

        return compareInt;
    }

}
